#include <X11/X.h>
#include <X11/Xlib.h>
#include <cstdio>
#include <cstdlib>

int main(int argc, char **argv) {
  Display *display;
  int screen;
  Window window;
  XEvent event;

  display = XOpenDisplay(NULL);

  if (display == NULL) {
    fprintf(stderr, "Can not open display\n");
    exit(1);
  }

  screen = DefaultScreen(display);

  window = XCreateSimpleWindow(display, RootWindow(display, screen), 200, 200,
                               500, 300, 1, BlackPixel(display, screen),
                               WhitePixel(display, screen));

  XSelectInput(display, window, ExposureMask | KeyPressMask);
  XMapWindow(display, window);
  while (true) {
    XNextEvent(display, &event);
  }

  return 0;
}
